﻿using ApiGateway.Interface;
using HttpService.Interface;

namespace HttpApiGateway.PlugIn
{
    /// <summary>
    /// IP黑名单
    /// </summary>
    internal class IpBackPlugIn : BasicPlugin
    {
        private readonly IIpBlackListPlugIn _Limit;
        public IpBackPlugIn()
        {
            _Limit = RpcClient.RpcClient.Unity.Resolve<IIpBlackListPlugIn>();
            _Init(_Limit);
        }

        public override void Exec(IRoute route, IHttpHandler handler)
        {
            if (_Limit.IsLimit(handler.Request.ClientIp))
            {
                handler.Response.SetHttpStatus(System.Net.HttpStatusCode.Forbidden);
                handler.Response.End();
            }
        }
    }
}
